// pages/index/index.js
Page({

   /**
    * 页面的初始数据
    */
   data: {
      // 键名：键值
      // 键值对
      Hei:"",
      winWid:"",
      swiperImg:[
         "../../images/swiper1.jpg",
         "../../images/swiper2.jpg",
         "../../images/swiper3.jpg"
      ],
      listImg:[
         "../../images/list1.png",
         "../../images/list2.png",
         "../../images/list3.png",
         "../../images/list4.png",
         "../../images/list5.png",
         "../../images/list6.png",
         "../../images/list7.png",
         "../../images/list8.png",
         "../../images/list9.png",
         "../../images/list10.png",
      ],
      selectList:[
         {
            titleImg:"../../images/select.jpg",
            goodsList:[
               {
                  id:1,
                  img:"../../images/select1.jpg",
                  title:"小米10小米10小米10小米10小米10小米10",
                  desc:"晓龙865/1亿像素相机晓龙865/1亿像素相机",
                  new:4999,
                  old:"",
                  detailsImg:[
                     "../../images/detailsImg/details-1.1.jpg",
                     "../../images/detailsImg/details-1.2.jpg",
                     "../../images/detailsImg/details-1.3.jpg",
                     "../../images/detailsImg/details-1.4.jpg",
                     "../../images/detailsImg/details-1.5.jpg",
                  ],
                  describeImg:[
                     "../../images/detailsImg/describe-1.1.jpg",
                     "../../images/detailsImg/describe-1.2.jpg",
                     "../../images/detailsImg/describe-1.3.jpg",
                     "../../images/detailsImg/describe-1.4.jpg",
                  ]
               },
               {
                  id:2,
                  img:"../../images/select2.jpg",
                  title:"小米10",
                  desc:"晓龙865/1亿像素相机",
                  new:4999,
                  old:"￥5999",
                  detailsImg:[
                     "../../images/detailsImg/details-1.1.jpg",
                     "../../images/detailsImg/details-1.2.jpg",
                     "../../images/detailsImg/details-1.3.jpg",
                     "../../images/detailsImg/details-1.4.jpg",
                     "../../images/detailsImg/details-1.5.jpg",
                  ],
                  describeImg:[
                     "../../images/detailsImg/describe-1.1.jpg",
                     "../../images/detailsImg/describe-1.2.jpg",
                     "../../images/detailsImg/describe-1.3.jpg",
                     "../../images/detailsImg/describe-1.4.jpg",
                  ]
               },
               {
                  id:3,
                  img:"../../images/select3.jpg",
                  title:"小米10",
                  desc:"晓龙865/1亿像素相机",
                  new:4999,
                  old:"￥5999",
                  detailsImg:[
                     "../../images/detailsImg/details-1.1.jpg",
                     "../../images/detailsImg/details-1.2.jpg",
                     "../../images/detailsImg/details-1.3.jpg",
                     "../../images/detailsImg/details-1.4.jpg",
                     "../../images/detailsImg/details-1.5.jpg",
                  ],
                  describeImg:[
                     "../../images/detailsImg/describe-1.1.jpg",
                     "../../images/detailsImg/describe-1.2.jpg",
                     "../../images/detailsImg/describe-1.3.jpg",
                     "../../images/detailsImg/describe-1.4.jpg",
                  ]
               },
               {
                  id:4,
                  img:"../../images/select4.jpg",
                  title:"小米10",
                  desc:"晓龙865/1亿像素相机",
                  new:4999,
                  old:"￥5999",
                  detailsImg:[
                     "../../images/detailsImg/details-1.1.jpg",
                     "../../images/detailsImg/details-1.2.jpg",
                     "../../images/detailsImg/details-1.3.jpg",
                     "../../images/detailsImg/details-1.4.jpg",
                     "../../images/detailsImg/details-1.5.jpg",
                  ],
                  describeImg:[
                     "../../images/detailsImg/describe-1.1.jpg",
                     "../../images/detailsImg/describe-1.2.jpg",
                     "../../images/detailsImg/describe-1.3.jpg",
                     "../../images/detailsImg/describe-1.4.jpg",
                  ]
               },
               {
                  id:5,
                  img:"../../images/select5.jpg",
                  title:"小米10",
                  desc:"晓龙865/1亿像素相机",
                  new:4999,
                  old:"￥5999",
                  detailsImg:[
                     "../../images/detailsImg/details-1.1.jpg",
                     "../../images/detailsImg/details-1.2.jpg",
                     "../../images/detailsImg/details-1.3.jpg",
                     "../../images/detailsImg/details-1.4.jpg",
                     "../../images/detailsImg/details-1.5.jpg",
                  ],
                  describeImg:[
                     "../../images/detailsImg/describe-1.1.jpg",
                     "../../images/detailsImg/describe-1.2.jpg",
                     "../../images/detailsImg/describe-1.3.jpg",
                     "../../images/detailsImg/describe-1.4.jpg",
                  ]
               },
               {
                  id:6,
                  img:"../../images/select6.jpg",
                  title:"小米10",
                  desc:"晓龙865/1亿像素相机",
                  new:4999,
                  old:"￥5999",
                  detailsImg:[
                     "../../images/detailsImg/details-1.1.jpg",
                     "../../images/detailsImg/details-1.2.jpg",
                     "../../images/detailsImg/details-1.3.jpg",
                     "../../images/detailsImg/details-1.4.jpg",
                     "../../images/detailsImg/details-1.5.jpg",
                  ],
                  describeImg:[
                     "../../images/detailsImg/describe-1.1.jpg",
                     "../../images/detailsImg/describe-1.2.jpg",
                     "../../images/detailsImg/describe-1.3.jpg",
                     "../../images/detailsImg/describe-1.4.jpg",
                  ]
               }
            ]
         },
         {
            titleImg:"../../images/select.jpg",
            goodsList:[
               {
                  id:7,
                  img:"../../images/select1.jpg",
                  title:"小米10小米10小米10小米10小米10小米10",
                  desc:"晓龙865/1亿像素相机晓龙865/1亿像素相机",
                  new:4999,
                  old:"",
                  detailsImg:[
                     "../../images/detailsImg/details-1.1.jpg",
                     "../../images/detailsImg/details-1.2.jpg",
                     "../../images/detailsImg/details-1.3.jpg",
                     "../../images/detailsImg/details-1.4.jpg",
                     "../../images/detailsImg/details-1.5.jpg",
                  ],
                  describeImg:[
                     "../../images/detailsImg/describe-1.1.jpg",
                     "../../images/detailsImg/describe-1.2.jpg",
                     "../../images/detailsImg/describe-1.3.jpg",
                     "../../images/detailsImg/describe-1.4.jpg",
                  ]
               },
               {
                  id:8,
                  img:"../../images/select2.jpg",
                  title:"小米10",
                  desc:"晓龙865/1亿像素相机",
                  new:4999,
                  old:"￥5999",
                  detailsImg:[
                     "../../images/detailsImg/details-1.1.jpg",
                     "../../images/detailsImg/details-1.2.jpg",
                     "../../images/detailsImg/details-1.3.jpg",
                     "../../images/detailsImg/details-1.4.jpg",
                     "../../images/detailsImg/details-1.5.jpg",
                  ],
                  describeImg:[
                     "../../images/detailsImg/describe-1.1.jpg",
                     "../../images/detailsImg/describe-1.2.jpg",
                     "../../images/detailsImg/describe-1.3.jpg",
                     "../../images/detailsImg/describe-1.4.jpg",
                  ]
               },
               {
                  id:9,
                  img:"../../images/select3.jpg",
                  title:"小米10",
                  desc:"晓龙865/1亿像素相机",
                  new:4999,
                  old:"￥5999",
                  detailsImg:[
                     "../../images/detailsImg/details-1.1.jpg",
                     "../../images/detailsImg/details-1.2.jpg",
                     "../../images/detailsImg/details-1.3.jpg",
                     "../../images/detailsImg/details-1.4.jpg",
                     "../../images/detailsImg/details-1.5.jpg",
                  ],
                  describeImg:[
                     "../../images/detailsImg/describe-1.1.jpg",
                     "../../images/detailsImg/describe-1.2.jpg",
                     "../../images/detailsImg/describe-1.3.jpg",
                     "../../images/detailsImg/describe-1.4.jpg",
                  ]
               },
               {
                  id:10,
                  img:"../../images/select4.jpg",
                  title:"小米10",
                  desc:"晓龙865/1亿像素相机",
                  new:4999,
                  old:"￥5999",
                  detailsImg:[
                     "../../images/detailsImg/details-1.1.jpg",
                     "../../images/detailsImg/details-1.2.jpg",
                     "../../images/detailsImg/details-1.3.jpg",
                     "../../images/detailsImg/details-1.4.jpg",
                     "../../images/detailsImg/details-1.5.jpg",
                  ],
                  describeImg:[
                     "../../images/detailsImg/describe-1.1.jpg",
                     "../../images/detailsImg/describe-1.2.jpg",
                     "../../images/detailsImg/describe-1.3.jpg",
                     "../../images/detailsImg/describe-1.4.jpg",
                  ]
               },
               {
                  id:11,
                  img:"../../images/select5.jpg",
                  title:"小米10",
                  desc:"晓龙865/1亿像素相机",
                  new:4999,
                  old:"￥5999",
                  detailsImg:[
                     "../../images/detailsImg/details-1.1.jpg",
                     "../../images/detailsImg/details-1.2.jpg",
                     "../../images/detailsImg/details-1.3.jpg",
                     "../../images/detailsImg/details-1.4.jpg",
                     "../../images/detailsImg/details-1.5.jpg",
                  ],
                  describeImg:[
                     "../../images/detailsImg/describe-1.1.jpg",
                     "../../images/detailsImg/describe-1.2.jpg",
                     "../../images/detailsImg/describe-1.3.jpg",
                     "../../images/detailsImg/describe-1.4.jpg",
                  ]
               },
               {
                  id:12,
                  img:"../../images/select6.jpg",
                  title:"小米10",
                  desc:"晓龙865/1亿像素相机",
                  new:4999,
                  old:"￥5999",
                  detailsImg:[
                     "../../images/detailsImg/details-1.1.jpg",
                     "../../images/detailsImg/details-1.2.jpg",
                     "../../images/detailsImg/details-1.3.jpg",
                     "../../images/detailsImg/details-1.4.jpg",
                     "../../images/detailsImg/details-1.5.jpg",
                  ],
                  describeImg:[
                     "../../images/detailsImg/describe-1.1.jpg",
                     "../../images/detailsImg/describe-1.2.jpg",
                     "../../images/detailsImg/describe-1.3.jpg",
                     "../../images/detailsImg/describe-1.4.jpg",
                  ]
               }
            ]
         }
      ]
   }, 

   // 计算图片缩放比后的高度函数
   imgH:function(event){
      // 获取图片的宽度和高度
      var imgWid = event.detail.width
      var imgHei = event.detail.height
      // imageWidth=imgWid    imageHeight=imgHei
      // console.log(imgWid)
      // console.log(imgHei)
      // 获取屏幕的宽度
      var winWid = wx.getSystemInfoSync().windowWidth
      // console.log(winWid)
      // 图片缩放后的高度
      var winHei = winWid / imgWid * imgHei
      // console.log(this)
      // 修改data里面的数据内容
      this.setData({
         Hei:winHei,
         winWid:winWid/2-10
      })
   },

   // 跳转到详情页
   toDetails:function(event){
      // 获取当前点击的商品对应的模块的下标值
      var id = event.target.dataset.id
      // 当前点击的商品对应的下标值
      var index = event.target.dataset.index
      // 获取所有的商品的数组
      var selectList = this.data.selectList
      // 当前点击对应的商品数据
      var good = selectList[id].goodsList[index]
      // 添加或修改详情页的缓存数据
      wx.setStorageSync('detailsList', [good])
      // 跳转到详情页
      wx.navigateTo({
        url: '/pages/details/details',
      })
      console.log("id ==>",id)
      console.log("index ==>",index)
      console.log("selectList ==>",selectList)
      console.log("good ==>",good)
   },

   /**
    * 生命周期函数--监听页面加载
    */
   onLoad: function (options) {
      // 同步  适用于代码量少的情况
      // wx.setStorageSync      添加/修改缓存数据
      // wx.removeStorageSync   删除缓存数据
      // wx.getStorageSync      获取缓存数据
      // wx.getStorageInfoSync  获取缓存数据信息
      // wx.clearStorageSync    清空所有的缓存数据

      // 异步  适用于代码量多的情况
      // wx.setStorage
      // wx.removeStorage
      // wx.getStorage
      // wx.getStorageInfo
      // wx.clearStorage

      wx.setStorageSync('indexList', this.data.selectList)
      // wx.removeStorageSync('logs')
      // var dataInfo = wx.getStorageInfoSync()
      // console.log(dataInfo)
      // var data = wx.getStorageSync('indexList')
      // console.log(data)
      // wx.clearStorageSync()
   },

   /**
    * 生命周期函数--监听页面初次渲染完成
    */
   onReady: function () {

   },

   /**
    * 生命周期函数--监听页面显示
    */
   onShow: function () {

   },

   /**
    * 生命周期函数--监听页面隐藏
    */
   onHide: function () {

   },

   /**
    * 生命周期函数--监听页面卸载
    */
   onUnload: function () {

   },

   /**
    * 页面相关事件处理函数--监听用户下拉动作
    */
   onPullDownRefresh: function () {

   },

   /**
    * 页面上拉触底事件的处理函数
    */
   onReachBottom: function () {

   },

   /**
    * 用户点击右上角分享
    */
   onShareAppMessage: function () {

   }
})